from django.shortcuts import render_to_response, get_object_or_404
from kitaplar.kitap.models import Author, UserProfile, Library, Book

def book(request):
	book_list = Book.objects.all().order_by('-title')
	return render_to_response('kitap/kitaplar.html', {'book_list': book_list})

def library(request):
	library_list = Library.objects.all().order_by('-name')
	return render_to_response('kitap/kutuphaneler.html', {'library_list': library_list})

def userprofile(request):
	userprofile_list = UserProfile.objects.all().order_by('-name')
	return render_to_response('kitap/uyeler.html', {'userprofile_list': userprofile_list})

def author(request):
	author_list = Author.objects.all().order_by('-name')
	return render_to_response('kitap/yazarlar.html', {'author_list': author_list})

def home(request):
	book_list = Book.objects.all().order_by('-title')[:7]
	library_list = Library.objects.all().order_by('-name')
	userprofile_list = UserProfile.objects.all().order_by('-name')[:7]
	author_list = Author.objects.all().order_by('-name')[:7]
	return render_to_response('kitap/anasayfa.html', {'book_list': book_list,
							'library_list': library_list,
							'userprofile_list': userprofile_list,
							'author_list': author_list})

def unique_book(request, book_id):
	unique_book = get_object_or_404(Book, pk=book_id)
	return render_to_response('kitap/kitap.html', {'unique_book': unique_book})

def unique_author(request, author_id):
	unique_author = get_object_or_404(Author, pk=author_id)
	return render_to_response('kitap/yazar.html', {'unique_author': unique_author})

def unique_library(request, library_id):
	unique_library = get_object_or_404(Library, pk=library_id)
	return render_to_response('kitap/kutuphane.html', {'unique_library': unique_library})
